package model;

import android.util.Log;

import base.BaseModel;
import base.BaseObserver;
import base.ResultCallBack;
import bean.CodeBean;
import bean.RegBean;
import bean.ResultBean;
import jiyun.com.yiyanmeng.http.HttpManager;
import jiyun.com.yiyanmeng.http.MySerivce;
import utils.RxUtil;

/**
 * Created by Windows on 2019/11/5.
 */

public class RegModel extends BaseModel {
    public void requestCode(String phoneNum, String s, final ResultCallBack<CodeBean> resultCallBack) {
        MySerivce serivce = HttpManager.getInstance().getSerivce();
        serivce.yanzhengma(phoneNum,s).compose(RxUtil.<ResultBean<CodeBean>>changeThread())
                .compose(RxUtil.<CodeBean>changeResult())
                .subscribe(new BaseObserver<CodeBean>() {
                    @Override
                    public void onSuccess(CodeBean codeBean) {
                        Log.i("tag", "onSuccess: "+codeBean.getMsg());
                        resultCallBack.onSuccess(codeBean);
                    }

                    @Override
                    public void onFail(String error) {
                        Log.i("tag", "onFail: "+error);
                        resultCallBack.onFail(error);


                    }
                });
    }

    public void reg(String phone, String password, int code, final ResultCallBack<RegBean> resultCallBack) {
        MySerivce serivce = HttpManager.getInstance().getSerivce();
        serivce.reg(phone,password,String.valueOf(code),"1")
                .compose(RxUtil.<ResultBean<RegBean>>changeThread())
                .compose(RxUtil.<RegBean>changeResult())
                .subscribe(new BaseObserver<RegBean>() {
                    @Override
                    public void onSuccess(RegBean regBean) {
                        Log.i("tag", "onSuccess: "+regBean.getUser_info().getPhnoe());
                        resultCallBack.onSuccess(regBean);

                    }

                    @Override
                    public void onFail(String error) {
                        Log.i("tag", "onFail: "+error);
                        resultCallBack.onFail(error);

                    }
                });

    }
}
